package co.com.services.ciudad;

import javax.naming.NamingException;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import co.com.smart.maestro.infraestructure.dto.CiudadDTO;
import co.com.smart.session.DelegateContextEJB;

@Path("/SmartCiudadServices")
public class CiudadService {
	
	@GET
	@Path("/getAllCiudad")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getCiudad() throws NamingException{
		return Response.ok(DelegateContextEJB.getCiudadBeanLocal().consultarAllCiudad())
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
	
	@POST
	@Path("/getCiudad")
	@Produces(MediaType.APPLICATION_JSON)
	public Response getAllCiudad(CiudadDTO json) throws NamingException{
		return Response.ok(DelegateContextEJB.getCiudadBeanLocal().consultarAllCiudad(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
	
	@POST
	@Path("/getCiudadId")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getCiudadId(CiudadDTO json) throws NamingException {
		return Response.ok(DelegateContextEJB.getCiudadBeanLocal().consultarCiudadId(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/setCiudad")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setCiudad( CiudadDTO json){ 
		return Response.ok(DelegateContextEJB.getCiudadBeanLocal().insertarCiudad(json))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	}

	@PUT
	@Path("/editCiudad")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setEditCiudad(CiudadDTO json){ 
		return Response.ok(DelegateContextEJB.getCiudadBeanLocal().editCiudad(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/removeCiudad")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setRemoveCiudad(CiudadDTO json){ 
		return Response.ok(DelegateContextEJB.getCiudadBeanLocal().removeCiudad(json, true))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
}
